package com.mashibing.flinkjava.code.chapter6.kryoser;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 序列化测试
 */
public class SerializerTest {
    public static void main(String[] args) throws Exception {
        //准备环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.getConfig().registerTypeWithKryoSerializer(Student.class,StudentSerializer.class);

        //source ,socket:1,zs,18
        DataStreamSource<String> ds = env.socketTextStream("mynode5", 9999);
        
        ds.map(new MapFunction<String, Student>() {

            @Override
            public Student map(String s) throws Exception {
                String[] arr = s.split(",");
                return new Student(Integer.valueOf(arr[0]),arr[1],Integer.valueOf(arr[2]));
            }
        }).print();
        env.execute();

    }
}
